package com.visikard.business;

import android.util.Log;

import com.visikard.application.Constant;
import com.visikard.item.CreateCouponParams;
import com.visikard.net.VKregisterNetworkException;
import com.visikard.request.CouponRequestManage;
import com.visikard.response.BaseResponse;
import com.visikard.response.CreateCpResponse;
import com.visikard.response.DeleteCouponResponse;
import com.visikard.response.GetListCouponResponse;

public class CouponBusManage {

	public CreateCpResponse createCoupon(String imageFile, String fkUser, String idUsersMerchant,
			CreateCouponParams params) {
		CouponRequestManage ar = new CouponRequestManage();
		CreateCpResponse result = new CreateCpResponse();
		try {

			String response = ar.createCouponRequest(imageFile, fkUser, idUsersMerchant, params);

			result.extractDataFromServer(response);
		}
		catch (VKregisterNetworkException e) {

			result.setErrorCode(BaseResponse.NETWORK_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		catch (Exception e) {

			result.setErrorCode(BaseResponse.UNKNOWN_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		return result;
	}

	public GetListCouponResponse getListCoupon(String fkUser, String timezone, String pageIndex, String pageSize) {
		CouponRequestManage ar = new CouponRequestManage();
		GetListCouponResponse result = new GetListCouponResponse();
		try {
			String response = ar.getListCouponRequest(fkUser, timezone, pageIndex, pageSize);
			result.extractDataFromServer(response);
		}
		catch (VKregisterNetworkException e) {
			Log.e(Constant.LOG_TAG, "getListCoupon: " + e.getMessage());
			result.setErrorCode(BaseResponse.NETWORK_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		catch (Exception e) {
			Log.e(Constant.LOG_TAG, "getListCoupon: " + e.getMessage());
			result.setErrorCode(BaseResponse.UNKNOWN_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		return result;
	}

	public DeleteCouponResponse deleteCoupon(String couponId) {
		CouponRequestManage ar = new CouponRequestManage();
		DeleteCouponResponse result = new DeleteCouponResponse();
		try {
			String response = ar.deleteCouponRequest(couponId);
			result.extractDataFromServer(response);
		}
		catch (VKregisterNetworkException e) {
			Log.e(Constant.LOG_TAG, "deleteCoupon: " + e.getMessage());
			result.setErrorCode(BaseResponse.NETWORK_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		catch (Exception e) {
			Log.e(Constant.LOG_TAG, "deleteCoupon: " + e.getMessage());
			result.setErrorCode(BaseResponse.UNKNOWN_ERROR);
			result.setErrorMsg(e.getMessage());
		}
		return result;
	}

}
